package com.example.spider.dianping;


import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import java.awt.*;

/**
 * @date 19-9-22
 * @auther jackliang
 * @description TODO
 */
public class Javax {

    static DocumentListener documentListener = new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            Document document = e.getDocument();
            try {
                String txt = document.getText(0, document.getLength());
                System.out.println(txt);
            } catch (BadLocationException e1) {
                e1.printStackTrace();
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {

        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }
    };


    public static void main(String[] args) {
        JFrame frame = new JFrame("....");
        //文本组件长度30
        JTextField cityTextFieldName = new JTextField(10);
        //带默认内容的文本组件，长度10
        JTextField classificationTextField = new JTextField(10);

        JTextField addressTextField = new JTextField(10);
//        addressTextField.getDocument().addDocumentListener(documentListener);
        JLabel cityLab = new JLabel("城市：");
        JLabel classificationLab = new JLabel("分类：");
        JLabel addressLab = new JLabel("地点：");

        //button

        JButton jButton = new JButton();
        jButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                System.out.println(addressTextField.getText());
            }
        });

        jButton.setLocation(100, 100);
        //设置组件的长度
        cityTextFieldName.setColumns(10);
        classificationTextField.setColumns(10);
        //设置默认文本组件不可编辑
//        noed.setEnabled(false);
        //使用网格布局
        frame.add(jButton);
        frame.setLayout(new GridLayout(5, 5));
        frame.add(cityLab);
        frame.add(cityTextFieldName);
        frame.add(classificationLab);
        frame.add(classificationTextField);
        frame.add(addressLab);
        frame.add(addressTextField);
        frame.setSize(400, 100);
        frame.setLocation(300, 200);
        frame.setVisible(true);
    }
}
